<!-- toast组件。tips：transition 在小程序中无效 -->
<template>
	<transition name="fade">
		<view v-if="_isShow" class="dam-flex_row dam-toast">
			<text class="text">{{_title}}</text>
		</view>
	</transition>
</template>

<script>
	export default {
		name: "dam-toast",
		props: {
			title: {
				type: String,
				default: ""
			}
		},
		data() {
			return {
				_isShow: false,
				_title: ''
			}
		},
		watch: {
			title(newVal, oldVal) {
				this._title = newVal
			}
		},
		methods: {
			show(title) {
				this._title = title
				if (!this._isShow) {
					let that = this;
					this._isShow = true;
					setTimeout(() => {
						that._isShow = false;
					}, 2000);
				}
			}
		}
	}
</script>

<style lang="scss">
	@import "/dam_common/styles/dam_animates.scss";

	.dam-toast {
		width: 90%;
		z-index: 1000;
		position: fixed;
		bottom: 6vh;
		left: 50%;
		justify-content: center;
		align-items: center;
		transform: translate(-50%, 0);
		-webkit-transform: translate(-50%, 0);
	}

	.dam-toast>.text {
		background-color: rgba(64, 64, 64, 0.7);
		border-radius: 30rpx;
		box-sizing: border-box;
		font-size: 30rpx;
		color: #ffffff;
		padding-left: 16rpx;
		padding-right: 16rpx;
		padding-top: 16rpx;
		padding-bottom: 16rpx;
		text-align: center;
	}

	/* 定义过渡效果 */
	.fade-enter,
	.fade-enter-active {
		@extend .dam-animate_fade-in;
	}

	.fade-leave-active,
	.fade-leave-to {
		@extend .dam-animate_fade-out;
	}
</style>